{%TEMPLATE->struct/head%}
{%TEMPLATE->struct/menu%}
<h2>Agent Binaries</h2>
{%TEMPLATE->struct/messages%}
{{IF [[newBinary]]}}
  <form action="binaries.php" method="post">
    <input type="hidden" name="action" value="[[$DAgentBinaryAction::NEW_BINARY]]">
    <input type="hidden" name="csrf" value="[[csrf]]">
    <div class="card">
      <div class="table-responsive">
        <table class="table table-bordered">
          <tr>
            <th>Type</th>
            <td><input type="text" name="type" class="form-control" value="" title="Type"></td>
          </tr>
          <tr>
            <th>Operating Systems</th>
            <td><input type="text" name="os" class="form-control" value="" title="Operating Systems"></td>
          </tr>
          <tr>
            <th>Filename (placed in 'bin' folder)</th>
            <td><input type="text" name="filename" class="form-control" value="" title="Filename"></td>
          </tr>
          <tr>
            <th>Version</th>
            <td><input type="text" name="version" class="form-control" value="" title="Version"></td>
          </tr>
          <tr>
            <th>Update Track</th>
            <td>
              <select class="form-control" name="updateTrack" title="Update Track">
                <option value="release">Release</option>
                <option value="stable" selected>Stable</option>
              </select>
            </td>
          </tr>
          <tr>
            <td colspan="2">
              <button type="submit" class="btn btn-success">Create</button>
            </td>
          </tr>
        </table>
      </div>
    </div>
  </form>
{{ENDIF}}
{{IF [[editBinary]]}}
  <form action="binaries.php" method="post">
    <input type="hidden" name="action" value="[[$DAgentBinaryAction::EDIT_BINARY]]">
    <input type="hidden" name="id" value="[[bin.getId()]]">
    <input type="hidden" name="csrf" value="[[csrf]]">
    <div class="card">
      <div class="table-responsive">
        <table class="table table-bordered">
          <tr>
            <th>Type</th>
            <td><input type="text" name="type" class="form-control" value="[[bin.getType()]]" title="Type"></td>
          </tr>
          <tr>
            <th>Operating Systems</th>
            <td><input type="text" name="os" class="form-control" value="[[bin.getOperatingSystems()]]" title="Operating Systems"></td>
          </tr>
          <tr>
            <th>Filename (placed in 'bin' folder)</th>
            <td><input type="text" name="filename" class="form-control" value="[[bin.getFilename()]]" title="Filename"></td>
          </tr>
          <tr>
            <th>Current Version (update here if you placed a new binary)</th>
            <td><input type="text" name="version" class="form-control" value="[[bin.getVersion()]]" title="Current Version"></td>
          </tr>
          <tr>
            <th>Update Track</th>
            <td>
              <select class="form-control" name="updateTrack" title="Update Track">
                <option value="release"{{IF [[bin.getUpdateTrack()]] == 'release'}} selected{{ENDIF}}>Release</option>
                <option value="stable"{{IF [[bin.getUpdateTrack()]] == 'stable'}} selected{{ENDIF}}>Stable</option>
              </select>
            </td>
          </tr>
          <tr>
            <td colspan="2">
              <button type="submit" class="btn btn-success">Save</button>
            </td>
          </tr>
        </table>
      </div>
    </div>
  </form>
{{ENDIF}}

<div class="card">
  <div class="table-responsive">
    <table class="table table-bordered">
      <tr>
        <td colspan="7">
          <a href="binaries.php?new=true" class="btn btn-success">Add New Binary</a>
        </td>
      </tr>
		  <tr>
			  <th>ID</th>
			  <th>Type</th>
			  <th>OS</th>
			  <th>Filename</th>
			  <th>Current Version</th>
			  <th>Update Track</th>
        <th>&nbsp;</th>
		  </tr>
		  {{FOREACH binary;[[binaries]]}}
			  <tr>
          <td>[[binary.getId()]]</td>
          <td>[[binary.getType()]]</td>
          <td>[[binary.getOperatingSystems()]]</td>
          <td><code>[[binary.getFilename()]]</code></td>
          <td>[[binary.getVersion()]]</td>
          <td><code>[[binary.getUpdateTrack()]]</code></td>
          <td>
            <form class="float-right" action="binaries.php" method="POST" onSubmit="if (!confirm('Really delete binary [[binary.getId()]]?')) return false;">
              <input type='hidden' name='action' value='[[$DAgentBinaryAction::DELETE_BINARY]]'>
              <input type="hidden" name="id" value="[[binary.getId()]]">
              <input type="hidden" name="csrf" value="[[csrf]]">
              <button type="submit" class='btn btn-danger mx-1' data-toggle="tooltip" data-placement="top" title="Delete"><i class="fas fa-trash" aria-hidden="true"></i></button>
            </form>
            {{IF [[binary.getUpdateAvailable()]]}}
              <form class="float-right" action="binaries.php" method="POST" onSubmit="if (!confirm('Are you sure you want to update to version [[binary.getUpdateAvailable()]]?')) return false;">
                <input type='hidden' name='action' value='[[$DAgentBinaryAction::UPGRADE_BINARY]]'>
                <input type="hidden" name="binaryId" value="[[binary.getId()]]">
                <input type="hidden" name="csrf" value="[[csrf]]">
                <button type="submit" class='btn btn-success mx-1' data-toggle="tooltip" data-placement="top" title="Upgrade to [[binary.getUpdateAvailable()]]"><i class="fas fa-cloud-download-alt" aria-hidden="true"></i></button>
              </form>
            {{ENDIF}}
            <form class="float-right" action="binaries.php" method="POST">
              <input type='hidden' name='action' value='[[$DAgentBinaryAction::CHECK_UPDATE]]'>
              <input type="hidden" name="binaryId" value="[[binary.getId()]]">
              <input type="hidden" name="csrf" value="[[csrf]]">
              <button type="submit" class='btn btn-warning mx-1' data-toggle="tooltip" data-placement="top" title="Check for Update"><i class="fas fa-sync" aria-hidden="true"></i></button>
            </form>
            <a href="binaries.php?edit=[[binary.getId()]]" class="btn btn-primary float-right mx-1" data-toggle="tooltip" data-placement="top" title="Edit"><i class="fas fa-edit" aria-hidden="true"></i></a>
          </td>
			  </tr>
		  {{ENDFOREACH}}
	  </table>
  </div>
</div>
{%TEMPLATE->struct/foot%}
